package com.asus.studyproject;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.widget.Toast;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by asus1 on 2017/10/15.
 */

public class MyService extends Service {

    Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            Toast.makeText(getApplicationContext(), message.what + "服务已启动", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    public MyService() {
    }


    @Override
    public int onStartCommand(Intent intent, int flags, final int startId) {

        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(startId);
            }
        }, 300, 500);


        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
